﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;


namespace WebApplication3
{
    public partial class CobroCaja : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void BtnComprar_Click(object sender, EventArgs e)
        {
            string nombre = "";
            string cantidad = "";
            
            int clave = 0;
            double precio = 0.00;
            double total = 0;

            try
            {
                string myConnectionString = "";

                if (myConnectionString == "")
                {
                    myConnectionString = "Database=inventario;Data Source=localhost;User Id=root;Password=123";
                }
                MySqlConnection myConnection = new MySqlConnection(myConnectionString);
                string mySelectQuery = "SELECT IdProducto, Nombre, Cant, Precio From producto Where IdProducto=" + txtClave.Text;
                MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection);
                myConnection.Open();
                MySqlDataReader myReader;
                myReader = myCommand.ExecuteReader();

                if (myReader.Read() == true)
                {
                    GridView1.Enabled = true;
                    clave = Convert.ToInt32(myReader["IdProducto"]);
                    nombre = myReader["Nombre"].ToString();
                    precio = Convert.ToDouble(myReader["Precio"]);
                    cantidad = myReader["Cant"].ToString();
                    
       
                

                    total = total + precio;
                    txtTotal.Text = Convert.ToString(total);

                    // txtCodigo.Clear();
                }
                else
                {
                    
                }


                myReader.Close();
                myConnection.Close();
            }
            catch (MySqlException)
            {
                //wmp_info.Play();
                //MessageBox.Show("Escribe el codigo");
            }
        }

        protected void BtnCompraTot_Click(object sender, EventArgs e)
        {
           
        }

   
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {




        }

        protected void txtClave_TextChanged(object sender, EventArgs e)
        {

        }

        protected void BtnCompraTot_Click_Click(object sender, EventArgs e)
        {
            Label5.Text = "Presionaste Boton de Realizar Venta";
        }

        protected void BtnComprar_Click_Click(object sender, EventArgs e)
        {
            string nombre = "";
            string cantidad = "";

            int clave = 0;
            double precio = 0.00;
            double total = 0;

            try
            {
                string myConnectionString = "";

                if (myConnectionString == "")
                {
                    myConnectionString = "Database=inventario;Data Source=localhost;User Id=root;Password=123";
                }
                MySqlConnection myConnection = new MySqlConnection(myConnectionString);
                string mySelectQuery = "SELECT IdProducto, Nombre, Cant, Precio From producto Where IdProducto=" + txtClave.Text;
                MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection);
                myConnection.Open();
                MySqlDataReader myReader;
                myReader = myCommand.ExecuteReader();

                if (myReader.Read() == true)
                {
                    GridView1.Enabled = true;
                    clave = Convert.ToInt32(myReader["IdProducto"]);
                    nombre = myReader["Nombre"].ToString();
                    precio = Convert.ToDouble(myReader["Precio"]);
                    cantidad = myReader["Cant"].ToString();




                    total = total + precio;
                    txtTotal.Text = Convert.ToString(total);

                    // txtCodigo.Clear();
                }
                else
                {

                }


                myReader.Close();
                myConnection.Close();
            }
            catch (MySqlException)
            {
                //wmp_info.Play();
                //MessageBox.Show("Escribe el codigo");
            }
        }

        
    }
}